// async await 是消灭异步回调的终极武器
// js还是单线程，还得有异步，还得基于 event loop
// async await是语法糖
// 执行async函数返回的一定是一个promise对象， await 后相当于promise then 返回promise中的内容


async function async1() {
  console.log('async1 start');//2
  await async2()
  // await 后面的都作为回调内容 --微任务
  console.log('async2 end'); //6
}

async function async2() {
  console.log('async2');//3
}

console.log('script start');//1

setTimeout(() => {//setTimeout 宏任务
  console.log('setTimeout');//8
}, 0);

async1()

//初始化 promise时，传入的函数回立即被执行
new Promise(function (resolve) {
  console.log('promise1');//4
  resolve()
}).then(function() {//promise 微任务
  console.log('promise2');//7
})

console.log('script end');//5




async function async1() {
  console.log('async1 start');
  await async2()
  console.log('async2 end');
}

async function async2() {
  console.log('async2');
}

console.log('script start');

setTimeout(() => {
  console.log('setTimeout');
}, 0);

async1()

new Promise(function (resolve) {
  console.log('promise1');
  resolve()
}).then(function() {
  console.log('promise2');
})

console.log('script end');